const utils = require('../../utils');

module.exports = function ({ host = 'localhost', port = 3306, user = 'root', password, database, table, sql, count = 1 }) {
  const mysql = require("mysql");
  const db = mysql.createConnection({ host, port, user, password, database });
  db.connect();
  const st = db.query(sql || `select * from ${table} limit ${count}`).stream();
  st.on("end", () => {
    db.end();
    utils.debug('mysqlReader [end]');
  });
  return st;
};